using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.Package;
using Microsoft.VisualStudio.TextManager.Interop;
using NBusiness.VisualStudio.Commands;

namespace NBusiness.VisualStudio
{
    internal class ESharpSource : Source
    {
        ESharpScanner _scanner;
        ESharpLanguageService _languageService;

        public ESharpSource(LanguageService language, IVsTextLines textLines, Colorizer colorizer)
            : base(language, textLines, colorizer)
        {
            _languageService = language as ESharpLanguageService;
            _scanner = colorizer.Scanner as ESharpScanner;
        }
        
        public event EventHandler Changed;

        public override void OnChangeLineText(TextLineChange[] lineChanges, int last)
        {
            if (Changed != null) 
                Changed(this, EventArgs.Empty);

            _scanner.Refresh();
            Recolorize(lineChanges);

            base.OnChangeLineText(lineChanges, last);
        }

        internal void Recolorize(TextLineChange[] lineChanges)
        {
            foreach (TextLineChange change in lineChanges)
                Recolorize(change.iStartLine, change.iNewEndLine);
        }

        public override void Completion(IVsTextView textView, TokenInfo info, ParseReason reason)
        {
            if (reason == ParseReason.MemberSelect)
            {
                reason = ParseReason.DisplayMemberList;
            }

            base.Completion(textView, info, reason);
        }
    }
}
